<?php

/**
 * Static content controller.
 *
 * This file will render views from views/pages/
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       app.Controller
 * @since         CakePHP(tm) v 0.2.9
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
App::uses('AppController', 'Controller');

/**
 * Static content controller
 *
 * Override this controller by placing a copy in controllers directory of an application
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers/pages-controller.html
 */
class VideosController extends AppController {

    var $name = 'Videos';
    public $components = array('Session');

    //Récupére toutes les videos d'un stade (id en paramètre)
    function portofolio($id) {
        if ($this->recherche == 'on')
            return $this->Video->find('all', array('conditions' => array('STADES_id_STADE' => $id, 'tags_VIDEO LIKE' => '%' . $this->cle . '%')));
        else
            return $this->Video->find('all', array('conditions' => array('STADES_id_STADE' => $id)));
    }

    //Ajouter vidéo
    function addvideos($id) {
        if ($this->request->is('post')) {

            //recup data form
            $d = $this->request->data;
            //val par défauts
            $d['Video']['id'] = null;
            $d['Video']['ajoute_par_VIDEO'] = AuthComponent::user('username');
            $d['Video']['STADES_id_STADE'] = $id;
            //req sql
            if ($this->Video->save($d, true, array('url_VIDEO', 'tags_VIDEO', 'ajoute_par_VIDEO', 'STADES_id_STADE'))) {
                $this->Session->setFlash(__('L ajout a été fait'));
                return $this->redirect(array('controller'=>'stades','action' => 'infostade',$id));
            } else {
                $this->Session->setFlash(__('Impossible d ajouter la video.'));
            }
        }
        else if($id = null){
            $this->redirect('/');
        }
    }
    
    //Rechercher vidéo selon le tag ($keys)
    function rechercher($keys){
        return $this->Video->find('all', array('fields' => 'STADES_id_STADE', 'conditions' => array('tags_VIDEO LIKE' => '%' . $keys . '%')));
    }

}
